package com.fuhaiwei.struts.action.impl;

import com.fuhaiwei.basic.utils.TextUtils;
import com.fuhaiwei.domain.service.LoginResult;
import com.fuhaiwei.struts.action.LoginAction;

public class LoginActionImpl extends LoginAction {

	public String execute() throws Exception {
		LoginResult result = getLoginService().doLogin(getUsername(),
				getPassword());
		if (result == LoginResult.LOGIN_SUCCESS) {
			getSession().put(SESSION_USER_NAME, getUsername());
			return SUCCESS;
		}
		if (result == LoginResult.PASSWORD_WORNG) {
			setTip(getTextUtils().text(TextUtils.INPUT_WRONG,
					getTextUtils().label(PASSWORD)));
			return INPUT;
		}
		if (result == LoginResult.USERNAME_NOTEXISTS) {
			setTip(getTextUtils().text(TextUtils.INPUT_NOTEXISTS,
					getTextUtils().label(USERNAME)));
			return INPUT;
		}
		if (result == LoginResult.DATABASE_ERROR) {
			setTip(getTextUtils().text(TextUtils.ERROR_DATABASE));
			return INPUT;
		}
		setTip(getTextUtils().text(TextUtils.ERROR_RETURN));
		return INPUT;
	}

}
